<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="礼券管理">
<style>
    .button-large {
        font-size: 16px;
    }
    hr {
        border-color: #009688;
    }
    .control-group {
        width: 1000px;
    }
    .webuploader-pick {
        background: none;
        padding: 0;
    }
</style>
<div class="xm-offline">
    <div class="row">
        <div class="panel">
            <div class="panel-header">
                <a href="${basepath}/rest/manage/voucher/toList">返回上一级</a>
            </div>
            <div class="panel-body">
            <#--form表单提交，相当于data-->
                <form id="addForm" class="form-horizontal" action="${basepath}/rest/manage/voucher/updateJson"
                      method="post">
                    <input type="hidden" name="id" value="${e.id!}">
                    <div class="control-group">
                        <label class="control-label">
                            <s>*</s>
                            礼券类型：
                        </label>
                        <div class="controls">
                            <div id="s1"><input type="hidden" id="hide" value="${e.type!}" name="type"></div>
                        </div>
                    </div>
                    <div class="control-group name">
                        <label class="control-label">
                            <s>*</s>
                            礼券名称：
                        </label>
                        <div class="controls">
                            <input type="text" class="control-text span-width inp span5"
                                   name="name" placeholder="请输入礼券名称" data-rules="{required:true}" value="${e.name!}">
                        </div>
                    </div>
                    <div class=" control-group start">
                        <label class="control-label">
                            <s>*</s>
                            开始日期：
                        </label>
                        <div class="time-controls controls">
                            <input name="startDate" class=" inp calendar bui-form-field-date bui-form-field span5"
                                   type="text" aria-disabled="false" aria-pressed="false" value="${e.startDate!}">
                        </div>
                    </div>
                    <div class=" control-group end">
                        <label class="control-label">
                            <s>*</s>
                            结束日期：
                        </label>
                        <div class="time-controls controls">
                            <input name="endDate" class=" inp calendar bui-form-field-date bui-form-field span5" type="text"
                                   aria-disabled="false" aria-pressed="false" value="${e.endDate!}">
                        </div>
                    </div>
                    <div class=" control-group discount">
                        <label class="control-label">
                            <s>*</s>
                            打折力度：
                        </label>
                        <div class="controls">
                            <input type="text" class="inp control-text span-width span5" value="${e.discount!}"
                                   name="discount" placeholder="请填写打折力度" data-rules="{required : true,number:true,max:1}">&nbsp;
                        </div>
                    </div>
                    <div class=" control-group validity">
                        <label class="control-label">
                            <s>*</s>
                            有效期：
                        </label>
                        <div class="controls">
                            <input type="text" class="inp control-text span-width span5" value="${e.indate!}"
                                   name="indate" placeholder="请填写有效期" data-rules="{required : true,number:true}">&nbsp;天
                        </div>
                    </div>
                    <div class=" control-group number">
                        <label class="control-label">
                            <s>*</s>
                            礼券面值：
                        </label>
                        <div class="controls">
                            <input type="number" class="inp control-text span-width span5" value="${e.money!}"
                                   name="money" placeholder="请填写礼券面值" >
                        </div>
                    </div>
                    <div class=" control-group limit">
                        <label class="control-label">
                            <s>*</s>
                            满减限制：
                        </label>
                        <div class="controls">
                            <input type="text" class="inp control-text span-width span5"  value="${e.limitMoney!}"
                                   name="limitMoney" placeholder="请填写满减限制" data-rules="{required : true,number:true}">
                        </div>
                    </div>
                    <div class=" control-group">
                        <label class="control-label"> <s>*</s>门槛介绍：</label>
                        <div class="controls control-row-auto mar0 ">
                                <textarea data-rules="{required:true}" class="span5 control-row4" value="${e.introduce!}"   name="introduce" placeholder="请填写门槛介绍">
                                </textarea>
                        </div>
                    </div>
                    <div class=" control-group">
                        <label class="control-label">
                            <s>*</s>
                            兑换积分：
                        </label>
                        <div class="controls">
                            <input type="text" class="control-text span-width span5" value="${e.score!}"
                                   name="score" placeholder="请填写兑换积分" data-rules="{required : true,number:true}">
                        </div>
                    </div>
                    <div class=" control-group">
                        <label class="control-label">
                            <s>*</s>
                            设置库存：
                        </label>
                        <div class="controls">
                            <input type="text" class="control-text span-width span5" value="${e.stock!}"
                                   name="stock" placeholder="请填写礼券库存" data-rules="{required : true,number:true}">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            <s>*</s>
                            商品主图：
                        </label>

                        <div class="controls" style="height: auto">
                            <input type="hidden" name="picture" value="${e.picture}"/>
                            <img id="mainPicture" src="${basepath}/${e.picture}"
                                 style="max-width: 250px;width: 100%;max-height: 250px;">
                            <a id="pictureBtn" class="button button-min button-primary pull-right hidden"
                               style="height:20px;margin-left: 10px;">上传</a>
                        </div>
                    </div>
                    <div class="centered">
                        <button type="submit" class="button  button-large  button-success">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var Store = BUI.Data.Store;
    var Data = BUI.Data;
    var Grid = BUI.Grid;
    var Calendar = BUI.Calendar;
    var datePicker = new Calendar.DatePicker({
        trigger: '.calendar-time',
        showTime: true,
        autoRender: true
    });
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType: 'ajax',
        callback: function (data) {
            if (data.success == true) {
                window.location.href = "${basepath}/rest/manage/voucher/toList"
            } else {
                BUI.Message.Alert(data.message, 'error');
                return;
            }
        }
    }).render();
    switch ('${e.type!}'){
        case 'cash':$('.type').val('代金券'); $('.control-group').show();$('.discount,.validity').hide().find('.inp').val(0);break;
        case 'discount':$('.type').val('打折劵'); $('.control-group').show();$('.validity,.number,.limit').find('.inp').val(0).end().hide();$('.start,.end').find('input').val('1970-01-01').end().hide();break;
        case 'birthday':$('.type').val('生日劵'); $('.control-group').show();$('.discount').find('.inp').val(0).end().hide();$('.start,.end').find('input').val('1970-01-01').end().hide();break;
    }
    BUI.use('bui/select', function (Select) {
        var items = [
                    {text: '代金券', value: 'cash'},
                    {text: '打折劵', value: 'discount'},
                    {text: '生日券', value: 'birthday'}
                ],
                select = new Select.Select({
                    render: '#s1',
                    valueField: '#hide',
                    items: items
                });
        select.render();
        select.on('change', function (ev) {
            $('.control-group').find('.inp').val("").end().show();
            switch (ev.item.value){
                case 'cash':$('.discount,.validity').find('input').val(0).end().hide();break;
                case 'discount':$('.validity,.number,.limit').find('input').val(0).end().hide(); $('.start,.end').find('input').val('1970-01-01').end().hide();break;
                case 'birthday':$('.discount').find('input').val(0).end().hide(); $('.start,.end').find('input').val('1970-01-01').end().hide();break;
            }
        });
    });

    /*------------------------图片上传插件配置  begin-----------------------*/
    var pictureUploader = WebUploader.create({
        auto: true,
        swf: '${staticpath}/common/ueditor/third-party/webuploader/Uploader.swf',
        server: '${basepath}/rest/manage/ued/config?action=uploadimage',
        pick: '#pictureBtn',
        resize: false,
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png,'
        }
    });

    pictureUploader.on('uploadSuccess', function (file, response) {
        pictureUploader.removeFile(file);
        addForm.setFieldValue("picture", response.url);
        $("#mainPicture").attr("src", "${basepath}/" + response.url);
    });
</script>

</@page.pageBase>